<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-3.1.1.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>病人管理</title>
<style type="text/css">
.cc_item {
	padding: 10px;
}
</style>
</head>
<body>
	<script type="text/javascript">
		$(function(){
			$("#cc_patient_ref").linkbutton({
				onClick : function() {
					$("#ccpatienttab").datagrid({
						url:"tocc_queryByAllpatient"
					});
				}
			});
			//tocc_querynotnullpaberthid
			$("#cc_querypbnotnull").linkbutton({
				onClick : function() {
					$("#ccpatienttab").datagrid({
						"url":"tocc_querynotnullpaberthid"
					});
				}
			});
			//tocc_querynullpaberthid
			$("#cc_querypbnull").linkbutton({
				onClick : function() {
					$("#ccpatienttab").datagrid({
						"url":"tocc_querynullpaberthid"
					});
				}
			});
			var pofficesno;
			$("#cc_patient_xiugai").linkbutton({
				onClick : function(index, row) {
					var rows = $("#ccpatienttab").datagrid("getSelections");
					if(rows.length == 1){
						
						pofficesno=rows[0].pofficesid;
						var pid=rows[0].patientid;
						$.getJSON("tocc_queryByOnepatient", {"pid": pid}, function(data){
							$("#cc_eait_patient_form").form("load", data);
							$("#pname").textbox("readonly",true);
							$("#icid").textbox("setValue",rows[0].icid);
							
							$("#icid").textbox("readonly",true);
							$("#patientid").val(pid);
						});
						$("#eait_patient_win").window("open");
					}else{
						$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
					}
				}
			});
			
			$("#pofficesid").combogrid({
				onChange:function(newValue,oldValue){
					var deptid= $("#pofficesid").combogrid("getValue");
					/* $.getJSON("tocc_queryByStaff", {"deptid": deptid}, function(data){
						$("#padoctorid").combogrid("setValue", data.staffNo);
						$("#padoctorid").combogrid("setText", data.staffName);
					}); */
					$("#padoctorid").combogrid({
			    		url:'tocc_queryByStaff',
			    		queryParams: {
			    			deptid: deptid
			    		}
			    	});
				}
			});
			var  shenpi_staffId = $("#tontyiStaffId").html();
			$("#cc_hpdoctorid").val(shenpi_staffId);
			$("#cc_uppatient_save").linkbutton({
				onClick : function() {
					//var cc_eee;
					var newpoff=$("#pofficesid").combogrid("getValue");
					if(pofficesno==newpoff){
						$('#cc_eait_patient_form').form({
							url:'tocc_updatepatientdoctor'
						});
					}else{
						$("#cc_old_offid").val(newpoff);
						$("#offDoctorid").val(shenpi_staffId);
						$('#cc_eait_patient_form').form({
							url:'tocc_updatepatientpoffice'
						});
						
					}
					$('#cc_eait_patient_form').form('submit', {
						onSubmit : function() {
							 //返回true提交表单，返回false则阻止表单提交
				             return $(this).form('validate');
						},
						success : function(data) {
							//JSON字符串两边需要添加小括号
							var json = eval("(" + data + ")");
							$.messager.alert("提示", json.reason);
							//关闭窗口
							$('#eait_patient_win').window('close');
							//重新加载数据
							$("#ccpatienttab").datagrid("reload");
							$(this).form("clear");
						}
					});
				}
			});
			//tocc_addCcOuthospital
			$("#cc_patient_out").linkbutton({
				onClick : function(index, row) {
					var rows = $("#ccpatienttab").datagrid("getSelections");
					if(rows.length == 1){
						if(rows[0].premarks!="已出院"){
							var patientid=rows[0].patientid;
							//用form提交
							$('<form>').form('submit', {
							    url:'tocc_addCcOuthospital',
							    onSubmit: function(param){
							    	param.patientid=patientid;
							    },
							    success:function(data){
							    	
							    	var json = eval("(" + data + ")");
									$.messager.alert("提示", json.reason);
									$("#ccpatienttab").datagrid("reload");
							    }
							});
						}
						
						
					}else{
						$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
					}
				}
			
			});
			$("#cc_patient_cancel").linkbutton({
				onClick:function(){
					$("#cc_eait_patient_form").form("clear");
					$("#eait_patient_win").window("close");
				}
			});
		});
		function cc_patientrowStlye(index,row){
			//alert(new Date());
			var date = new Date();
		    var seperator1 = "/";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    if (row.ppdate==currentdate){
				return 'background-color:#CCFF99;color:red;';
				
			}
		}
	</script>
	<div style="display: none">
		<input id="cc_hpdoctorid" name="hpdoctorid" class="easyui-textbox"
			>
	</div>
	<table id="ccpatienttab" class="easyui-datagrid"
		data-options="
							fitColumns:true,
							fit:true,
							rownumbers: true,
							striped:true,
						    url: 'tocc_queryByAllpatient',
							border:false ,
							pagination:true,
							pageSize: 16,
							pageList:[16,32,64,128],
							toolbar: '#cc_patient_btn',
							rowStyler:cc_patientrowStlye
						">
		<thead>
			<tr>
				<th data-options="field:'patientid',width:'6%',checkbox:true">住院号</th>
				<th data-options="field:'icid', width:'8%'">病人IC卡</th>
				<th data-options="field:'pname', width:'8%'">病人姓名</th>
				<th data-options="field:'psex', width:'5%'">性别</th>
				<th data-options="field:'paage', width:'5%'">年龄</th>
				<th data-options="field:'staffName', width:'8%'">主治医生</th>
				<th data-options="field:'pofficesid', width:'8%'">科室编号</th>
				<th data-options="field:'departmentName', width:'9%'">所属科室</th>
				<th data-options="field:'bname',width:'8%'">床位号</th>
				<th data-options="field:'wname', width:'8%'">病房名称</th>
				<th data-options="field:'wmoney', width:'6%'">日消费</th>
				<th data-options="field:'waddress', width:'10%'">病房地址</th>
				<th data-options="field:'ppdate', width:'9%'">入住日期</th>
				<th data-options="field:'premarks', width:'7%'">状态</th>
				
			</tr>
		</thead>
	</table>

	<div id="cc_patient_btn">
		<a id="cc_querypbnull" class="easyui-linkbutton"
			data-options="iconCls:'icon-weiruzhu',plain:true">查看未入住的病人</a>
			<a id="cc_querypbnotnull" class="easyui-linkbutton"
			data-options="iconCls:'icon-ruzhu',plain:true">查看已入住的病人</a>
			<a id="cc_patient_xiugai" class="easyui-linkbutton"
			data-options="iconCls:'icon-zhuanyi',plain:true">修改资料</a>
			 <a id="cc_patient_out" class="easyui-linkbutton"
			data-options="iconCls:'icon-shengqingout',plain:true">申请出院</a>
			<a id="cc_patient_ref" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a><input
			id="cc_patientsearch" class="easyui-searchbox"
			data-options="menu:'#cc_berthee',width:220,prompt:'请输入你要查找的内容'">
	</div>
	<div id="cc_berthee" style="width: 90px">
		<div date-options="name:'name'">病人姓名</div>
		<div date-options="name:'name'">病房科室</div>
		<div date-options="name:'name'">病房名称</div>
	</div>

	<div id="eait_patient_win" class="easyui-window"
			style="padding:10px;line-height: 150%;background: rgb(236,243,255);"
			data-options="
			iconCls:'icon-banliyewu',
		     width: 370,
		     height: 220,
		      modal:true,
		     closed: true,
		     title:'病人信息修改'
			">
			
				<form id="cc_eait_patient_form" action="" method="post">
					<div style="display: none">
						<input id="offDoctorid" name="offDoctorid">
						<input id="patientid" name="patientid">
						<input id="cc_old_offid" name="old_offid">
					</div>
					<div class="cc_item">
						<input id="pname" name="pname" class="easyui-textbox"
							data-options="label: '病人姓名:',labelAlign:'right', width: 260">
					</div>
					<div class="cc_item">
						<input id="icid" name="icid" class="easyui-textbox"
							data-options="label: '病人IC卡号:', labelAlign:'right', width: 260">
					</div>
					
					<div class="cc_item">
						<select id="pofficesid" name="pofficesid" class="easyui-combogrid" data-options="
							labelAlign:'right', width: 260,
							label:'科室:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '科室不能为空',
							panelWidth: '303',
							pagination:true,
							pageSize: 6,
							pageList:[6,12,24,48],
							url: 'queryTbdepartment',
							idField: 'departmentNo',
							textField: 'departmentName',
							columns: [[
								{field: 'departmentNo', title: '科室编号', width: 120},
								{field: 'departmentName', title: '科室名称', width: 180},
							]]
						"></select>
					</div>
					<div class="cc_item">
					<select id="padoctorid" name="padoctorid" class="easyui-combogrid" data-options="
							labelAlign:'right', width: 260,
							label:'主治医生:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '主治医生不能为空',
							panelWidth: '233',
							url: 'queryTbstaff',
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field: 'staffNo', title: '医生编号', width: 80},
								{field: 'staffName', title: '医生姓名', width: 80},
								{field: 'departmentName', title: '科室', width: 60},
							]]
						"></select>
					</div>
					
					
					<div style="margin-left:20%;padding-top:5px">
						<a id="cc_uppatient_save"  class="easyui-linkbutton" data-options="iconCls:'icon-baocun'">确定</a>
						 <a id="cc_patient_cancel" style="margin-left:40px" class="easyui-linkbutton" data-options="iconCls:'icon-chexiao'">取消</a>
					</div>
	
				</form>
		
	</div>
</body>
</html>